package com.hava.orm.jpa;

import java.util.List;

/**
 * Created by zhanpeng on 15-11-30.
 */
public class UUIDAutoService <T>{
    AutoRepository repository;

    //目前来说必要的function
    //让spring把注入的对象应用在通用function
    public AutoRepository getRepository() {
        return repository;
    }

    public void setRepository(AutoRepository repository) {
        this.repository = repository;
    }

    public void create(T entity)
    {
        getRepository().save(entity);
    }

    public void delete(String id)
    {
        getRepository().delete(id);
    }

    public void update(T entity)
    {
        getRepository().save(entity);
    }

    public T get(String id)
    {
        return (T)getRepository().findOne(id);
    }

    public List<T> getAll()
    {
        return (List<T>)getRepository().findAll();
    }
}